define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		function get_data_addressList(result) {
			if(false) {
				result = '{"success": true,"msg": "","result":'+ 
				'{"addr_id": "001","name": "张三","region_id": "001","addr": "上大路123号","zip": "200000","mobile": "18912345678","def_addr": "true"},'+
				'"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		};
		function get_data_addressDefault(result){
			if(false) {
				result = '{"success": true,"msg": "","result": {"addr_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		};
		function get_data_addressDelete(result){
			if(false) {
				result = '{"success": true,"msg": "","result": {"addr_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}
		
		//返回信息
		return {
			//地址一览
			address_list: function(nPage,addr_id,callback,calldone) {
				Http.post({
					method: 'member.address.getlist',
					addr_id: addr_id,
					pagelimit:10,
					nPage:nPage
				}, function(result) {
					//函数回调
					if(callback)
						callback(get_data_addressList(result).result);
				}, function(e) {

				}, function() {
					if(calldone)
						calldone();
				});
			},
			//删除
			address_delete:function(addr_id,callback){
				Http.post({
					method:'member.address.deladdr',
					addr_id:addr_id
				},function(result){
					if(callback)
						callback(get_data_addressDelete(result));
				},function(e){
					
				},function(){
					
				})
			},
			//设置默认
			address_default:function(addr_id,callback){
				Http.post({
					method:'member.address.setdefault',
					addr_id:addr_id
				},function(result){
					if(callback)
						callback(get_data_addressDefault(result));
				},function(e){
					
				},function(){
					
				})
			}
			
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("T_address", factory);
});